import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';
import { Workbox } from 'workbox-window';

import { default as http } from './common/api/request';
import store from './stores';
import Root from './router/index';
import '../styles';
import './svg';

window.$get = http.get;
window.$post = http.post;
window.$put = http.put;
window.$delete = http.delete;

const rootHtml = document.getElementById('root');
ReactDOM.render(
  <BrowserRouter>
    <Provider store={store}>
      <Root />
    </Provider>
  </BrowserRouter>,
  rootHtml
);

if ('serviceWorker' in navigator) {
  const wb = new Workbox('../sw.js');
  // wb.addEventListener("installed", (event) => {
  //   if (event.isUpdate) {
  //     if (confirm("检查有新版，是否更新最新?")) {
  //       window.location.reload();
  //     }
  //   }
  // });
  wb.register();
}
